package com.noshufou.android.su;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.LocalSocketAddress.Namespace;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.tech.Ndef;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.noshufou.android.su.provider.PermissionsProvider.Apps;
import com.noshufou.android.su.util.Util;
import java.io.IOException;
import java.io.OutputStream;

public class SuRequestActivity extends Activity
  implements View.OnClickListener
{
  private static final String TAG = "Su.SuRequestActivity";
  private int mAttempts = 3;
  private int mCallerUid = 0;
  private String mDesiredCmd = "";
  private int mDesiredUid = 0;
  private ViewFlipper mFlipper;
  private TextView mMoreInfo;
  private NfcAdapter mNfcAdapter = null;
  private EditText mPinText;
  private SharedPreferences mPrefs;
  private CheckBox mRememberCheckBox;
  private LocalSocket mSocket;
  private int mSuVersionCode = 0;
  private boolean mUsePin = false;
  private View.OnClickListener onPinButton = new View.OnClickListener()
  {
    public void onClick(View paramView)
    {
      Button localButton = (Button)paramView;
      SuRequestActivity.this.mPinText.append(localButton.getText());
    }
  };

  private void flipInfo()
  {
    this.mFlipper.showNext();
    if (this.mFlipper.getDisplayedChild() == 0)
      this.mMoreInfo.setText(2131427379);
    while (true)
    {
      return;
      this.mMoreInfo.setText(2131427380);
    }
  }

  private void sendResult(boolean paramBoolean1, boolean paramBoolean2)
  {
    String str;
    if (paramBoolean1)
      str = "ALLOW";
    while (true)
    {
      int i;
      if (paramBoolean2)
      {
        ContentValues localContentValues = new ContentValues();
        localContentValues.put("uid", Integer.valueOf(this.mCallerUid));
        localContentValues.put("package", Util.getAppPackage(this, this.mCallerUid));
        localContentValues.put("name", Util.getAppName(this, this.mCallerUid, false));
        localContentValues.put("exec_uid", Integer.valueOf(this.mDesiredUid));
        localContentValues.put("exec_cmd", this.mDesiredCmd);
        if (paramBoolean1)
        {
          i = 1;
          localContentValues.put("allow", Integer.valueOf(i));
          getContentResolver().insert(PermissionsProvider.Apps.CONTENT_URI, localContentValues);
        }
      }
      else
      {
        SharedPreferences.Editor localEditor = this.mPrefs.edit();
        localEditor.putBoolean("last_remember_value", this.mRememberCheckBox.isChecked());
        int j = this.mPrefs.getInt("pref_timeout", 0);
        if ((j > 0) && (paramBoolean1))
          localEditor.putLong("active_" + this.mCallerUid, System.currentTimeMillis() + j * 1000);
        localEditor.commit();
      }
      try
      {
        OutputStream localOutputStream = this.mSocket.getOutputStream();
        Log.i("Su.SuRequestActivity", "Sending result: " + str + " for UID: " + this.mCallerUid);
        localOutputStream.write(str.getBytes("UTF-8"));
        localOutputStream.flush();
        localOutputStream.close();
        this.mSocket.close();
        finish();
        return;
        str = "DENY";
        continue;
        i = 0;
      }
      catch (IOException localIOException)
      {
        while (true)
          Log.e("Su.SuRequestActivity", "Failed to write to socket", localIOException);
      }
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    case 2131361866:
    case 2131361868:
    case 2131361872:
    case 2131361873:
    default:
    case 2131361865:
    case 2131361869:
    case 2131361867:
    case 2131361870:
    case 2131361871:
    case 2131361874:
    }
    while (true)
    {
      return;
      if (this.mUsePin)
      {
        this.mAttempts = (-1 + this.mAttempts);
        if (Util.checkPin(this, this.mPinText.getText().toString()))
        {
          sendResult(true, this.mRememberCheckBox.isChecked());
          continue;
        }
        if (this.mAttempts > 0)
        {
          this.mPinText.setText("");
          EditText localEditText = this.mPinText;
          Resources localResources = getResources();
          int i = this.mAttempts;
          Object[] arrayOfObject = new Object[1];
          arrayOfObject[0] = Integer.valueOf(this.mAttempts);
          localEditText.setHint(localResources.getQuantityString(2131492866, i, arrayOfObject));
          this.mPinText.setHintTextColor(-65536);
          continue;
        }
        sendResult(false, false);
        continue;
      }
      sendResult(true, this.mRememberCheckBox.isChecked());
      continue;
      sendResult(false, this.mRememberCheckBox.isChecked());
      continue;
      flipInfo();
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    if (getCallingPackage() != null)
    {
      Log.e("Su.SuRequestActivity", "SuRequest must be started from su");
      finish();
    }
    while (true)
    {
      return;
      this.mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
      Intent localIntent = getIntent();
      this.mCallerUid = localIntent.getIntExtra("caller_uid", 0);
      this.mDesiredUid = localIntent.getIntExtra("desired_uid", 0);
      this.mDesiredCmd = localIntent.getStringExtra("desired_cmd");
      String str = localIntent.getStringExtra("socket");
      this.mSuVersionCode = localIntent.getIntExtra("version_code", 0);
      this.mUsePin = this.mPrefs.getBoolean("pref_pin", false);
      if (this.mUsePin)
      {
        setContentView(2130903046);
        ViewGroup localViewGroup = (ViewGroup)findViewById(2131361814);
        this.mPinText = ((EditText)localViewGroup.findViewById(2131361855));
        ((Button)localViewGroup.findViewById(2131361866)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361856)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361857)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361858)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361859)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361860)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361861)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361862)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361863)).setOnClickListener(this.onPinButton);
        ((Button)localViewGroup.findViewById(2131361864)).setOnClickListener(this.onPinButton);
        ((Button)findViewById(2131361865)).setOnClickListener(this);
        ((Button)findViewById(2131361867)).setOnClickListener(this);
      }
      try
      {
        while (true)
        {
          this.mSocket = new LocalSocket();
          this.mSocket.connect(new LocalSocketAddress(str, LocalSocketAddress.Namespace.FILESYSTEM));
          if (this.mSuVersionCode < 10)
            Util.showOutdatedNotification(this);
          TextView localTextView = (TextView)findViewById(2131361872);
          Object[] arrayOfObject = new Object[1];
          arrayOfObject[0] = Util.getAppName(this, this.mCallerUid, false);
          localTextView.setText(getString(2131427378, arrayOfObject));
          ((TextView)findViewById(2131361820)).setText(Util.getAppName(this, this.mCallerUid, true));
          ((TextView)findViewById(2131361824)).setText(Util.getAppPackage(this, this.mCallerUid));
          ((TextView)findViewById(2131361828)).setText(Util.getUidName(this, this.mDesiredUid, true));
          ((TextView)findViewById(2131361830)).setText(this.mDesiredCmd);
          this.mRememberCheckBox = ((CheckBox)findViewById(2131361813));
          this.mRememberCheckBox.setChecked(this.mPrefs.getBoolean("last_remember_value", true));
          this.mFlipper = ((ViewFlipper)findViewById(2131361871));
          this.mMoreInfo = ((TextView)findViewById(2131361874));
          if (!this.mPrefs.getBoolean("pref_advanced_prompt", false))
            break label684;
          this.mFlipper.setDisplayedChild(1);
          this.mMoreInfo.setVisibility(8);
          break;
          setContentView(2130903045);
          ((Button)findViewById(2131361869)).setOnClickListener(this);
          ((Button)findViewById(2131361870)).setOnClickListener(this);
        }
      }
      catch (IOException localIOException)
      {
        while (true)
        {
          Log.e("Su.SuRequestActivity", "Failed to connect to socket", localIOException);
          finish();
        }
        label684: this.mFlipper.setOnClickListener(this);
        this.mMoreInfo.setOnClickListener(this);
      }
    }
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramInt == 4) || (paramInt == 3))
      sendResult(false, false);
    return super.onKeyDown(paramInt, paramKeyEvent);
  }

  public void onNewIntent(Intent paramIntent)
  {
    Parcelable[] arrayOfParcelable = paramIntent.getParcelableArrayExtra("android.nfc.extra.NDEF_MESSAGES");
    if (arrayOfParcelable != null)
    {
      NdefRecord localNdefRecord = ((android.nfc.NdefMessage)arrayOfParcelable[0]).getRecords()[0];
      int i = localNdefRecord.getTnf();
      String str = new String(localNdefRecord.getType());
      if ((i == 2) && (str.equals("text/x-su-a")) && (new String(localNdefRecord.getPayload()).equals(this.mPrefs.getString("pin", ""))))
        sendResult(true, this.mRememberCheckBox.isChecked());
    }
  }

  protected void onPause()
  {
    super.onPause();
    if (this.mNfcAdapter != null)
      this.mNfcAdapter.disableForegroundDispatch(this);
  }

  protected void onResume()
  {
    super.onResume();
    PendingIntent localPendingIntent;
    IntentFilter localIntentFilter;
    if (this.mPrefs.getBoolean("pref_use_allow_tag", false))
    {
      this.mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
      localPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(536870912), 0);
      localIntentFilter = new IntentFilter("android.nfc.action.NDEF_DISCOVERED");
    }
    try
    {
      localIntentFilter.addDataType("text/x-su-a");
      IntentFilter[] arrayOfIntentFilter = new IntentFilter[1];
      arrayOfIntentFilter[0] = localIntentFilter;
      String[][] arrayOfString; = new String[1][];
      String[] arrayOfString = new String[1];
      arrayOfString[0] = Ndef.class.getName();
      arrayOfString;[0] = arrayOfString;
      this.mNfcAdapter.enableForegroundDispatch(this, localPendingIntent, arrayOfIntentFilter, arrayOfString;);
      return;
    }
    catch (IntentFilter.MalformedMimeTypeException localMalformedMimeTypeException)
    {
      while (true)
        Log.e("Su.SuRequestActivity", "Bad MIME type declared", localMalformedMimeTypeException);
    }
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.SuRequestActivity
 * JD-Core Version:    0.6.0
 */